#include <twit/Twitter.h>
#include <stdio.h>

/*
#if defined(WIN32)||defined(_WIN32)
#  if _DEBUG
#     pragma comment(lib,"../../../lib/twit4cppd.lib")
#  else
#     pragma comment(lib, "../../lib/twit4cpp.lib")
#  endif
#endif
*/

#if defined(WIN32)||defined(_WIN32)
#     pragma comment(lib,"../../../lib/twit4cpp.lib")
#endif
using namespace std;
using namespace Twit;

class UserStreamImpl:public IUserStream
{
	virtual void onFriendList(Value::IDs userIDs)
	{
		// following list.
		printf("\n* %-40s ------------\n", __FUNCTION__);
		for(size_t i=0; i<userIDs.size(); i++)
		{
			puts(userIDs[i].toString().c_str());
		}
	}

	virtual void onStatus(Value::Status status)
	{
		printf("\n* %-40s ------------\n", __FUNCTION__);
		puts(status.getUser()->getScreenName().c_str());
		wprintf(L"text : %s\n", status.getText().c_str());
	}
   virtual void onDeleteStatus         (Value::UniqueID userId, Value::UniqueID statusId)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("userid:%s\n", userId.toString().c_str());
      printf("statusid:%s\n", statusId.toString().c_str());
   }

   virtual void onDeleteDirectMessage  (Value::UniqueID userId, Value::UniqueID dmId)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("userid:%s\n", userId.toString().c_str());
      printf("dmid:%s\n", dmId.toString().c_str());
   }
   virtual void onDirectMessage(Value::DirectMessage dm)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("recipient:%s\n",dm.getRecipientScreenName().c_str());
      printf("sender:%s\n", dm.getSenderScreenName().c_str());
   }
   virtual void onUserUpdate(Value::User user)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("userId:%s\n", user.getId().toString().c_str());
   }
   virtual void onFollow(Value::User source, Value::User target)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
	  printf("source : %s\n", source.getScreenName().c_str());
	  printf("target : %s\n", target.getScreenName().c_str());
   }
   virtual void onUnfollow(Value::User source, Value::User target)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
	  printf("source : %s\n", source.getScreenName().c_str());
	  printf("target : %s\n", target.getScreenName().c_str());
   }

   virtual void onBlock    (Value::User source, Value::User target)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("source:%s\n", source.getScreenName().c_str());
      printf("target:%s\n", target.getScreenName().c_str());
   }
   virtual void onUnblock  (Value::User source, Value::User target)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("source:%s\n", source.getScreenName().c_str());
      printf("target:%s\n", target.getScreenName().c_str());
   }

   virtual void onFavorite(Value::User source, Value::User target, Value::Status targetObject)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("source:%s\n", source.getScreenName().c_str());
      printf("target:%s\n", target.getScreenName().c_str());
      printf("object:%s\n", targetObject.getId().toString().c_str());
   }
   virtual void onUnfavorite(Value::User source, Value::User target, Value::Status targetObject)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("source:%s\n", source.getScreenName().c_str());
      printf("target:%s\n", target.getScreenName().c_str());
      printf("object:%s\n", targetObject.getId().toString().c_str());
   }
   virtual void onListMemberAdded(Value::User owner, Value::List targetObject)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("owner:%s\n", owner.getScreenName().c_str());
      printf("fullname:%s\n", targetObject.getFullName().c_str());
   }
   virtual void onListMemberRemoved (Value::User owner, Value::List targetObject)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("owner:%s\n", owner.getScreenName().c_str());
      printf("fullname:%s\n", targetObject.getFullName().c_str());
   }
   virtual void onListDestroyed  (Value::User owner,Value::List targetObject)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("owner:%s\n", owner.getScreenName().c_str());
      printf("fullname:%s\n", targetObject.getFullName().c_str());
   }
   virtual void onListCreated    (Value::User owner, Value::List targetObject)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("owner:%s\n", owner.getScreenName().c_str());
      printf("object:%s\n", targetObject.getFullName().c_str());
   }

   virtual void onListUserSubscribed   (Value::User source, Value::User target, Value::List targetObject)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("source:%s\n", source.getScreenName().c_str());
      printf("target:%s\n", target.getScreenName().c_str());
      printf("object:%s\n", targetObject.getFullName().c_str());
   }
   virtual void onListUserUnsubscribed (Value::User source, Value::User target, Value::List targetObject)
   {
	   printf("\n* %-40s ------------\n", __FUNCTION__);
      printf("source:%s\n", source.getScreenName().c_str());
      printf("target:%s\n", target.getScreenName().c_str());
      printf("object:%s\n", targetObject.getFullName().c_str());
   }
};

int main(int argc, char* argv[])
{
   /* twit4cpp Sample Application */
   try
   {
      string
         customerKey("2rBtCAh5o10zMlS2FbRYAA"),
         customerSecert("MoZvHvDGbi6zoPu6Q1SZHsalGynP8qWt9dlB1NKlvQg");

	  UserStreamImpl us;
      Twitter twit(customerKey, customerSecert);

		std::string aToken("access token"),
		  aSecret("access token secret");

	  twit.setAccessToken(aToken,aSecret);
      
	  Error err;
	  if(!twit.UserStream.start(us, err))
	  {
		  printf("error userstream : %s\n", err.getMessage().c_str());
	  }
     while(1)
     {
		 // do something...
		 Sleep(10000);
		 // twit.UserStream.stop();
     }
   }
   catch(const Error& e)
   {
      printf("code : %d\n", e.getCode());
      printf("message : %s\n", e.getMessage().c_str());
   }   

   puts("Press Any Key...");
   fflush(stdin);
   getc(stdin);
	return 0;
}

